<?php /*
	*/ ?>
<?php
include("system/config.inc.php");

// Id admin is not logedin
if(!isset($_SESSION['userid']))
{
	header("location:adminlogin.php");
	die();
}
// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")
{
	$varemail = $_REQUEST['email'];
	$varinitial = $_REQUEST['initial'];
	$varfirstname = $_REQUEST['fname'];
	$varlastname = $_REQUEST['lname'];
	$varcountry = $_REQUEST['selectcountry'];
	$varstate = $_REQUEST['selectstate'];
	$varcitytown = $_REQUEST['selecttown'];
	$varzippostal = $_REQUEST['postcode'];
	$varusername = $_REQUEST['username'];
	$varpassword = $_REQUEST['password'];
	$varquestion = $_REQUEST['selectques'];
	$varanswer = $_REQUEST['answer'];
	//$intstatus = $_REQUEST['occasion'];
	//$dtregdate = $_REQUEST['occasion'];
	//$inttotallogin = $_REQUEST['occasion'];
	
	$insert="INSERT INTO `tblmember` ( `varemail` , `varinitial` , `varfirstname` , `varlastname` , `varcountry` , `varstate` , `varcitytown` , `varzippostal` , `varusername` , `varpassword` , `varquestion` , `varanswer` , `intstatus` , `dtregdate` , `inttotallogin` ) 
VALUES ('$varemail', '$varinitial', '$varfirstname', '$varlastname', '$varcountry', '$varstate', '$varcitytown', '$varzippostal', '$varusername', '$varpassword', '$varquestion', '$varanswer', '0', NOW(), '0')";
	$sql=$obj_db->insert($insert);
	header("location:member.php");
	die();
}	

// DELETE record from database
if(isset($_REQUEST['action']) && trim($_REQUEST['action'])==3)
{
	if(isset($_REQUEST['id']) && trim($_REQUEST['id']!=""))
	{	
		$id =  $_REQUEST['id'];
		$sql_del = "Delete from tblmember where intid ='$id'";
		$del = $obj_db->sql_query($sql_del);
		header("location:member.php");
		die();
	}
}
// UPDATE the record
$email = "";
$initial = "";
$firstname = "";
$lastname = "";
$country = "";
$state = "";
$citytown = "";
$zippostal = "";
$username = "";
$password = "";
$question = "";
$answer = "";
$action=1;
if((isset($_REQUEST['action']) && trim($_REQUEST['action'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")))
{
 	if(isset($_REQUEST['id']) && trim($_REQUEST['id']!=""))
 	{
		$id =  $_REQUEST['id'];
		$sql = "select * from tblmember where intid ='$id'";
		$result = $obj_db->select($sql);
		if(count($result)<=0)
		{
			echo " No Record Found!<br>";
			die();
		}
		if($result)
		{
			foreach($result as $row)
			{
				$email = $row['varemail'];
				$initial = $row['varinitial'];
				$firstname = $row['varfirstname'];
				$lastname = $row['varlastname'];
				$country = $row['varcountry'];
				$state = $row['varstate'];
				$citytown = $row['varcitytown'];
				$zippostal = $row['varzippostal'];
				$username = $row['varusername'];
				$password = $row['varpassword'];
				$question = $row['varquestion'];
				$answer = $row['varanswer'];
				$action=2;
			}
		}
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update")
		{
			$varemail = $_REQUEST['email'];
			$varinitial = $_REQUEST['initial'];
			$varfirstname = $_REQUEST['fname'];
			$varlastname = $_REQUEST['lname'];
			$varcountry = $_REQUEST['selectcountry'];
			$varstate = $_REQUEST['selectstate'];
			$varcitytown = $_REQUEST['selecttown'];
			$varzippostal = $_REQUEST['postcode'];
			//$varusername = $_REQUEST['username'];
			//$varpassword = $_REQUEST['password'];
			$varquestion = $_REQUEST['selectques'];
			$varanswer = $_REQUEST['answer'];
			//$intstatus = $_REQUEST['occasion'];
			//$dtregdate = $_REQUEST['occasion'];
			//$inttotallogin = $_REQUEST['occasion'];
			
			$sql_upd ="UPDATE tblmember SET  varemail = '$varemail',
			 varinitial = '$varinitial', varfirstname = '$varfirstname', 
			 varlastname = '$varlastname', varcountry = '$varcountry', varstate = '$varstate',
			 varcitytown = '$varcitytown', varzippostal = '$varzippostal', 
			
			 varquestion = '$varquestion', varanswer = '$varanswer', dtregdate = NOW() 
			 WHERE intid ='$id'";
			 
			$result = $obj_db->sql_query($sql_upd);
			$action=1;
			header("location:member.php");
			die();
		}
	}
}
// change status disable or active
if(isset($_REQUEST['sltstatus']))
{
	if(isset($_REQUEST['s']) && trim($_REQUEST['s']) == 0)
	 {
		if(isset($_REQUEST['id']) && trim($_REQUEST['id']!=""))
		{
			$id=$_REQUEST['id'];
			$sql="update tblmember set intstatus = 1 where intid = $id";
			$update = $obj_db->sql_query($sql);
			header("location:member.php");
			die();
		}
	}
	if(isset($_REQUEST['s']) && trim($_REQUEST['s']) == 1)
	{
		if(isset($_REQUEST['id']) && trim($_REQUEST['id']!=""))
		{
			$id=$_REQUEST['id'];
			$sql="update tblmember set intstatus = 0 where intid = $id";
			$update = $obj_db->sql_query($sql);
			header("location:member.php");
			die();
		}
	}
}


// change status disable or active
if(isset($_REQUEST['upgrd']))
{
	if(isset($_REQUEST['s']) && trim($_REQUEST['s']) == 0)
	 {
		if(isset($_REQUEST['id']) && trim($_REQUEST['id']!=""))
		{
			$id=$_REQUEST['id'];
			$sql="update tblmember set intpay = 2 where intid = $id";
			$update = $obj_db->sql_query($sql);
			header("location:member.php?msg=upgrade");
			die();
		}
	}
	if(isset($_REQUEST['s']) && trim($_REQUEST['s']) == 1)
	{
		if(isset($_REQUEST['id']) && trim($_REQUEST['id']!=""))
		{
			$id=$_REQUEST['id'];
			$sql="update tblmember set intpay = 1 where intid = $id";
			$update = $obj_db->sql_query($sql);
			header("location:member.php");
			die();
		}
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
<title>virtualfit.com.au</title>
<link href="css/rest.css" rel="stylesheet" type="text/css" />
</head>
<script language="javascript" src="js/member.js"></script>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td align="center" valign="top" ><?php include(INC."top.inc.php"); ?></td>
</tr>
<tr>
<td>

<table width="100%" border="0" cellspacing="5" cellpadding="5" align="center">
  <tr>
    <td><table width="100%"  border="0" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>

<?php
if(isset($_REQUEST['script']))
{
	if(trim($_REQUEST['script'])=='add' || trim($_REQUEST['script'])=='edit')
	{
	?>
<form name="form" method="post" action="" >
  <table align="center" cellpadding="2" cellspacing="2" class="border1">
	<tr>
	<td class="line_top">	  
	  Member...</td>
	</tr>	
	<tr >
	  <td>	  
	  <table border="0" cellspacing="2" cellpadding="2" class="tfont">
	<tr>
		<td width="56" class="register">First Name:<span class="blueNote">*</span></td>
		<?php if(isset($_REQUEST['fname']))
		  { $firstname=$_REQUEST['fname'];  }		?>
		<td width="120"><input name="fname" type="text" class="txt" id="fname" value="<?=$firstname;?>" size="14"></td>
		<td width="40" class="register">Initial:</td>
		<?php if(isset($_REQUEST['initial']))
		  { $initial=$_REQUEST['initial'];  }		?>		
		<td width="110"><input name="initial" type="text" class="txt" id="initial" value="<?=$initial;?>" size="14"></td>
		<td width="68" class="register">Last Name:<span class="blueNote">*</span></td>
		<?php if(isset($_REQUEST['lname']))
		  { $lastname=$_REQUEST['lname'];  }		?>				
		<td width="134"><input name="lname" type="text" class="txt" id="lname" value="<?=$lastname;?>" size="15"></td>
		<td width="63" class="register">Email Address:<span class="blueNote">*</span></td>
		<?php if(isset($_REQUEST['email']))
		  { $email=$_REQUEST['email'];  }		?>						
		<td width="108"><input name="email" type="text" class="txt" id="email" value="<?=$email;?>" size="18"></td>
	</tr>
	<tr>
		<td colspan="2" align="right">&nbsp;</td>
		<td colspan="6" class="register" align="left">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="8" class="note">Please select the states, County and town/city that most closely represents your location.</td>
	</tr>
		<td class="register">Country:</td>
		<td><input type="text" name="selectcountry" id="selectcountry" value="<?=$country;?>"/></td> 	
		
		<td class="register">State:</td>
		<td><input type="text" name="selectstate" id="selectstate" value="<?=$state;?>"/></td>
		
		<td class="register">Town/City:</td>
		<td><input type="text" name="selecttown" id="selecttown" value="<?=$citytown;?>"/></td>
		<td class="register">Post Code:<span class="blueNote">*</span></td>
		<?php if(isset($_REQUEST['postcode']))
		  { $zippostal=$_REQUEST['postcode'];  }		?>								
		<td><input name="postcode" type="text" class="txt" id="postcode" value="<?=$zippostal;?>" size="12"></td>
	</tr>
	<tr>
		<td colspan="8">&nbsp;</td>
	</tr>
	<!--<tr>
		<td>&nbsp;</td>
		<td class="register"></span>Username:</td>
		<?php if(isset($_REQUEST['username']))
		  { $username=$_REQUEST['username'];  }		?>										
		<td colspan="2"><input name="username" type="text" class="txt" id="username" value="<?=$username;?>"></td>
		<td class="register" colspan="2" align="right">Password:</td>
		<?php if(isset($_REQUEST['password']))
		  { $password=$_REQUEST['password'];  }		?>												
		<td colspan="2"><input name="password" type="password" class="txt" id="password" value="<?=$password;?>" <? if(trim($_REQUEST['script'])=='edit'){ ?> disabled="disabled" <? } ?>/></td>		
	</tr>-->
	
	<tr>
		<td class="register" align="left" colspan=2"">&nbsp;</td>
		<?php if(isset($_REQUEST['cpassword']))
		  { $password=$_REQUEST['cpassword'];  }		?>														
		<td colspan="6">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="8">&nbsp;</td>
	</tr>
	<tr>
		<td class="register" align="left" colspan=2"">Please choose a  question:</span></td>
		<td colspan="6"  title="76"><input type="text" name="selectques" id="selectques" value="<?=$question;?>"/></td>
	</tr>
	<tr>
		<td class="register" align="left" colspan=2"">Answer to  question:</td>
		<?php if(isset($_REQUEST['answer']))
		  { $answer=$_REQUEST['answer'];  }		?>														
		<td colspan="6"><input name="answer" type="text" class="txt" id="answer" value="<?=$answer;?>" size="90"/></td>
	</tr>
	<tr>
		<td colspan="2" align="right">&nbsp;</td>
		<td colspan="6" class="register" align="left">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="8" align="center"><input name="Submit" type="submit" class="button" onClick="return check();" value="<?php echo ($action==2) ? "Update":"Submit"; ?>" /></td>
		</tr>
</table>
 	  </td>
	</tr>
	</table>
	<?
	}
}
else
{
?>
<br>
<table border="0" align="center" cellpadding="1" cellspacing="0" class="border">
	  <tr>
		<td height="20">
		<table border="0" align="center" cellpadding="1" cellspacing="0" width="100%">
			<tr align="center" class="line_top">
				<td align="left">Member</td>
				<td align="right"><a class="link" href="member.php?script=add">New</a></td>
			</tr>
		</table>
		</td>
	  </tr>

		<td >
		<table  border="0" align="center" cellpadding="2" cellspacing="2" class="tfont">
		  <tr class="header1">
			<td align="center">Fullname</td>
			<td align="center">Email</td>
			<td align="center">Change Status</td>
			<td align="center">Detail</td>
			<td align="center">Change Membership</td>
			<td align="center">Edit</td>
			<td align="center">Delete</td>
		  </tr>
	<?
		/**************************************
		PAGING CODE START
		**************************************/
		$tablename="tblmember";
		$per_page_keywords= "intpay!='3'";
		$per_page_sorts="";
		include("system/paging.inc.php");
		
		/**************************************
		PAGING CODE ENDING
		**************************************/


	$sql_select = "select * 
	from  ".$tablename."
	where ".$per_page_keywords."
	Limit ".($page_no*$row_per_page).",".$row_per_page;
	$sql = $obj_db->select($sql_select);
	if(count($sql)>0)
	{
	$i=0;
	 for($j=0;$j<count($sql);$j++)
	 { 
		 $i=$i+1;
		  ?>
			<tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onMouseOut="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">        
				<td><?php echo $sql[$j]['varfirstname']." ".$sql[$j]['varinitial']; ?></td>
				<td align="center"><?php echo $sql[$j]['varemail']; ?></td>
				<td align="center"><?php
				if($sql[$j]['intstatus']==0)
				{
					$id = $sql[$j]['intid'];
					echo "<a href='member.php?sltstatus=0&s=0&id=$id' title='Click Here to Enable'>Enable</a>";	
				} 
				if($sql[$j]['intstatus']==1)
				{
					$id = $sql[$j]['intid'];
					echo "<a href='member.php?sltstatus=1&s=1&id=$id' title='Click Here to Disable'>Disable</a>";	
				}
				?></td>

				<td><a href="memberdetail.php?id=<?=$sql[$j]['intid'];?>" title="Click here for detail of member.">Detail</a></td>
				
				<td align="center"><?php
				if($sql[$j]['intpay']==1)
				{
					$id = $sql[$j]['intid'];
					echo "<a href='member.php?upgrd=1&s=0&id=$id' title='Click Here to become a paid member'>Free member</a>";	
				} 
				if($sql[$j]['intpay']==2)
				{
					$id = $sql[$j]['intid'];
					echo "<a href='member.php?upgrd=2&s=1&id=$id' title='Click Here to become a free member'>Paid member</a>";	
				}
				?></td>
				
				<td align="center">
				<a class="link" href="member.php?script=edit&action=2&id=<?php echo $sql[$j]['intid']; ?>" title="Click Here to Edit"><img src="images/edit.bmp" border="0" /></a></td>
				<td align="center">
				<a class="link" href="member.php?action=3&id=<?php echo $sql[$j]['intid']; ?>" onClick="return confirm('Are you sure to delete this record ?');" title="Click Here to Delete"><img src="images/delete.bmp" border="0" /></a></td>
	        </tr>
  <?php 
		}
		?>
		<tr >
			  <td colspan="6" align="center"><?
pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);
?>
             </td>
		  </tr>
		  <?
	}	
   ?>
  </table></td>
  </tr>
</table>	
</form>
<?
}
?></td>
      </tr>
    </table></td>
  </tr>
</table>


</td>
</tr>
<tr><td align="center"><?php include(INC."bottom.inc.php"); ?></td></tr>
</table>
</body>
</html>